{% extends 'base_children.html' %}
{% load mytags %}
{% block content %}
    <div class="layui-row larryms-panel auth-user-add">
        <form action="{% url 'mysql_fast_sql_api' %}" class="layui-form layui-form-pane" method="PUT" id="demoAddForm">
            {% csrf_token %}
         <input class="layui-input" name="id"  value="{{ data.id }}" type="hidden">




                    <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">sql标题</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="name" lay-verify="required" value="{{ data.name }}" type="text" required>
                        </div>
                    </div>

                            <div class="layui-inline">
                        <label class="layui-form-label">功能描述</label>
                        <div class="layui-input-block">
                            <input class="layui-input" name="desc" value="{{ data.desc }}" type="text">
                        </div>
                    </div>

                     <div class="layui-inline">
                        <label class="layui-form-label">执行分类</label>
                        <div class="layui-input-block">
                            <select name="exec_posi" >
                                    {% for s in sql_exec_typ %}
                                                 {% ifequal s.1 data.exec_posi %}
                                     <option value="{{ s.0 }}" selected> {{ s.1 }}</option>
                                            {% else %}
                                            <option value="{{ s.0 }}"> {{ s.1 }}</option>
                                        {% endifequal %}
                                    {% endfor %}
                            </select>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">

                        <label class="layui-form-label">SQL</label>
                        <div class="layui-input-block">
                            <textarea class="layui-textarea" name="sql" >{{ data.sql }}</textarea>
                        </div>
                </div>

            <div class="larryms-layer-btn">
                {#                    <a class="layui-btn layui-btn layui-btn-sm  layui-btn-normal" id="testconn">测试连接</a>#}
                <a class="layui-btn layui-btn layui-btn-sm left" lay-submit="" lay-filter="demoadd"
                   id="submitAdd">确定</a>
                <a class="layui-btn layui-btn layui-btn-sm  layui-btn-danger" id="resetAdd">重置</a>
                <a class="layui-btn layui-btn layui-btn-sm  layui-btn-danger" id="closeAdd">关闭</a>
            </div>


        </form>
    </div>

{% endblock %}
{% block self_foot %}
    <script type="text/javascript">
        layui.config({
            version: "2.0.8",
            base: '/static/larryms/',
            layertype: 2, //iframe内层弹窗类型不显示返回首页
            rightMenu: false // false关闭，设置为custom时使用自定义，不使用默认menu
        }).extend({
            larry: 'js/base'
        }).use(['larry', 'layer', 'table','jquery','form'], function () {
        var $ = layui.$,
             layer=layui.layer,

            table=layui.table,
            larryms = layui.larryms,
            form = layui.form;

            var curIfr = parent.layer.getFrameIndex(window.name);
            $('#resetAdd').on('click', function () {
                $('#demoAddForm')[0].reset();
            });
            $('#closeAdd').on('click', function () {
                parent.layer.close(curIfr);
            });
            form.on('submit(demoadd)', function (data) {
                  $.ajax({
			    dataType: "JSON",
			    url:data.form.action, //请求地址
			    type:"PUT",  //提交类似
			    contentType: "application/json",
			    data: JSON.stringify(data.field),  //提交参数
			    success:function(res) {
			           if (res.code == 200) {
                        larryms.msg(res.msg);
                        parent.table.reload('demo',{});
                        parent.layer.close(curIfr);

                        // $('#demoAddForm')[0].reset();继续添加注销上一段
                        {#larryms.msg(res.msg, {time: 350}, function () {#}
                        {#    parent.table.reload('demo', {});#}
                        {#    parent.layer.close(curIfr);#}
                        {# })#}

                    }else if (res.code == 500) {
                        larryms.msg(res.msg);
                    }

                }


                });
                return false;
            });

        });


    </script>

{% endblock %}